package com.sgb.kjwl.viewmodel.self.publish;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.model.entity.DeviceAttrEntity;
import com.sgb.kjwl.model.entity.DeviceDetailEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.DeviceRepertory;
import com.sgb.kjwl.view.ui.activity.self.publish.DevicePublishDetailActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;

import java.util.List;

import io.reactivex.functions.Consumer;
@Deprecated
public class DevicePublishDetailModel extends BaseViewModel {
    private DevicePublishDetailActivity activity;
    private DeviceRepertory repertory;

    public DevicePublishDetailModel(DevicePublishDetailActivity activity, DeviceRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getDetail(String id) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        repertory.getDeviceDetail(id).subscribe(new Consumer<DeviceDetailEntity>() {
            @Override
            public void accept(DeviceDetailEntity data) throws Exception {
                DialogHelper.dismissProgressDialog();
                activity.showDetail(data);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, throwable.getMessage());
            }
        });
    }

    public void getAttr(String id) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        repertory.getDeviceAttr(id).subscribe(new Consumer<BaseEntity<ListResponse<List<DeviceAttrEntity>>>>() {
            @Override
            public void accept(BaseEntity<ListResponse<List<DeviceAttrEntity>>> data) throws Exception {
                DialogHelper.dismissProgressDialog();
                activity.showAttr(data.getData().getList());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, throwable.getMessage());
            }
        });
    }
}
